<template>
    <div class="box">
        <div class="title"><span class="tag"></span>财务利润测算</div>
        <div class="">
            <FormItems
                ref="form"
                v-model="info"
                :form="formList"
                :state="state"
            ></FormItems>
        </div>
    </div>
</template>

<script>
import FormItems from "@/views/finance/manage/formItems/index.vue";
export default {
    components: { FormItems },
    props: {
        value: {
            required: false,
        },
        state: {
            required: false,
        },
        type: {
            required: false,
        },
    },
    data() {
        return {};
    },
    inject: ["details_forecast", "details_config"],
    computed: {
        formData: {
            get() {
                return this.value;
            },
            set(val) {
                this.$emit("input", val);
            },
        },
        config() {
            return this.details_config();
        },
        details() {
            return this.details_forecast();
        },
        calcSnapshoot() {
            if (
                this.formData.calcSnapshoot &&
                typeof this.formData.calcSnapshoot == "string"
            ) {
                return JSON.parse(this.formData.calcSnapshoot);
            } else {
                return this.formData.calcSnapshoot ?? {};
            }
        },
        info() {
            return this.calcSnapshoot?.financialProfitCalcResult ?? {};
        },
        formList() {
            return [
                {
                    label: "租赁利润",
                    prop: "leasingProfit",
                    format: (row) => {
                        let price = row?.leasingProfit * 1;
                        return Number.isFinite(price)
                            ? this.format_thousand(price?.toFixed(2))
                            : "-";
                    },
                },
                {
                    label: "处置利润",
                    prop: "disposalProfit",
                    format: (row) => {
                        let price = row?.disposalProfit * 1;
                        return Number.isFinite(price)
                            ? this.format_thousand(price?.toFixed(2))
                            : "-";
                    },
                },
                {
                    label: "利息支出",
                    prop: "interestExpense",
                    format: (row) => {
                        let price = row?.interestExpense * 1;
                        return Number.isFinite(price)
                            ? this.format_thousand(price?.toFixed(2))
                            : "-";
                    },
                },
                {
                    label: "税前利润",
                    prop: "profitBeforeTax",
                    format: (row) => {
                        let price = row?.profitBeforeTax * 1;
                        return Number.isFinite(price)
                            ? this.format_thousand(price?.toFixed(2))
                            : "-";
                    },
                },
                {
                    label: "净利润",
                    prop: "netProfit",
                    format: (row) => {
                        let price = row?.netProfit * 1;
                        return Number.isFinite(price)
                            ? this.format_thousand(price?.toFixed(2))
                            : "-";
                    },
                },
                {
                    label: "租赁毛利率",
                    prop: "totalLeasingProfit",
                    format: (row) => {
                        let price = this.numberRide(
                            row?.leasingGrossProfitMargin,
                            100
                        );
                        if (isNaN(price)) return "-";
                        let priceT = this.format_thousand(price?.toFixed(2));
                        return priceT ? priceT + "%" : "-";
                    },
                },
            ];
        },
    },
    created() {},
    mounted() {},
    methods: {
        valid() {
            return new Promise(async (resolve) => {
                let result = true;
                let refs = Object.values(this.$refs);
                for (let index = 0; index < refs?.length; index++) {
                    const ref = refs[index];
                    if (
                        Object.prototype.toString.call(ref) == "[object Array]"
                    ) {
                        for (let i = 0; i < ref.length; i++) {
                            const element = ref[i];
                            if (element?.valid) {
                                let rc = await element?.valid?.();
                                result = result && rc;
                            }
                            if (element?.validate) {
                                let rf = await this._valid(ref);
                                result = result && rf;
                            }
                            if (element?.form_validate) {
                                let rf = await this._valid(
                                    ref,
                                    "form_validate"
                                );
                                result = result && rf;
                            }
                        }
                    } else {
                        if (ref?.valid) {
                            let rc = await ref?.valid?.();
                            result = result && rc;
                        }
                        if (ref?.validate) {
                            let rf = await this._valid(ref);
                            result = result && rf;
                        }
                        if (ref?.form_validate) {
                            let rf = await this._valid(ref, "form_validate");
                            result = result && rf;
                        }
                    }
                }

                resolve(result);
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.box {
    border-radius: 8px;
    background-color: #fff;
    .title {
        font-size: 14px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 22px;
        padding-bottom: 15px;
        // border-bottom: 1px solid #e9e9e9;
        display: flex;
        align-items: center;
        .tag {
            width: 8px;
            height: 8px;
            background-color: #1890ff;
            border-radius: 100%;
            margin-right: 10px;
        }
        .price {
            font-size: 14px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            color: #1890ff;
            line-height: 20px;
            margin-left: 20px;
        }
    }
}
::v-deep .el-input-number {
    width: 100%;
    .el-input-number__decrease,
    .el-input-number__increase {
        display: none;
    }
    input {
        width: 100%;
        padding: 5px;
        text-align: left;
    }
}
</style>
